<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>预约列表</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理
            <small>检查项列表</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>检查项列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="pagination.currentPage=1;findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新增</el-button>
            </div>
            <el-table @selection-change="handleSelectionChange" size="small" current-row-key="id" :data="dataList"
                      stripe highlight-current-row>
                <el-table-column
                        type="selection"
                        width="55">
                </el-table-column>

                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号码" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" size="mini" @click="handleUpdate(scope.row)">修改预约</el-button>
                        <el-button size="text" type="danger" @click="handleDelete(scope.row)">删除预约</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约"  :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="会员信息" name="first">
                                <el-form label-position="right" :model="formData" label-width="100px" ref="dataAddForm" :rules="rules">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="身份证" prop="idCard">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="手机号" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="年龄" prop="age">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="性别" prop="region">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="婚姻状态" prop="marraiage">
                                                <el-input v-model="formData.marraiage"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="预约时间" prop="date1">
                                                <el-date-picker type="date" placeholder="选择日期"
                                                                v-model="formData.orderDate" style="width: 100%;"
                                                                value-format="yyyy-MM-dd"></el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐名称</th>
                                            <th>套餐介绍</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="checkitemIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑预约信息" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="会员信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="预约日期">
                                                    <el-input v-model="formData.orderDate" type="textarea"></el-input>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-col :span="12">
                                            <el-form-item label="档案号">
                                                <el-input :disabled="true" v-model="formData.fileNumber"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input :disabled="true" v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="手机号" prop="phoneNumber">
                                                <el-input :disabled="true" v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="预约类型">
                                                <el-input :disabled="true" v-model="formData.orderType"/>
                                            </el-form-item>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐名称</th>
                                            <th>套餐介绍</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="checkitemIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td><label>{{c.name}}</label></td>
                                            <td><label>{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            tableData: [],//新增和编辑表单中对应的套餐数据
            checkitemIds: [],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            multipleSelection: [],//多选框的json数组
            rules: {//校验规则
                name: [{required: true, message: '姓名为必填项', trigger: 'blur'}],
                phoneNumber: [
                    {required: true, message: '手机号为必填项', trigger: 'blur'},
                    {min: 11, max: 11, message: '长度在 11 个字符', trigger: 'blur'}
                ],
                idCard: [
                    {required: true, message: '身份证为必填项', trigger: 'blur'},
                    {min: 18, max: 18, message: '长度在 18 个字符', trigger: 'blur'}
                ],
                age: [{required: true, message: '年龄为必填项', trigger: 'blur'}],
                marraiage: [{required: true, message: '婚姻状态为必填项', trigger: 'blur'}]
            }

        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            //编辑
            handleEdit() {
                console.log(this.checkitemIds);
                    if (this.checkitemIds.length==1){
                            //表单数据校验通过，
                            axios.post("/order/updateOrder?id="+this.checkitemIds[0], this.formData).then((response) => {
                                this.dialogFormVisible4Edit = false;
                                if (response.data.flag) {
                                    this.$message({
                                        type: 'success',
                                        message: response.data.message
                                    });
                                } else {
                                    this.$message.error(response.data.message);
                                }
                            }).finally(() => {
                                this.findPage();
                            });
                    }else {
                        this.$message.error("至多选一个套餐，谢谢配合");
                    }
            },
            //添加
            handleAdd() {
                this.$refs['dataAddForm'].validate((valid) => {
                    if (valid) {
                        //表单数据校验通过，
                        axios.post("/ordersetting/addOrder?ids="+this.checkitemIds, this.formData).then((response) => {
                            this.dialogFormVisible = false;
                            if (response.data.flag) {
                                this.$message({
                                    type: 'success',
                                    message: response.data.message
                                });
                            } else {
                                this.$message.error(response.data.message);
                            }
                        }).finally(() => {
                            this.findPage();
                        });
                    } else {
                        this.$message.error("表单数据校验失败");
                        return false;
                    }
                });
            },
            //前面的选中的行的json数据
            handleSelectionChange(val) {
                // this.$alert(val);
                this.multipleSelection = val;

            },
            delectByCriteria() {
                axios.post("/checkitem/delectByCriteria", this.multipleSelection).then((res) => {
                    if (res.data.flag) {
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });
                    } else {
                        this.$message({
                            type: 'warning',
                            message: res.data.message
                        });
                    }
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '批量删除失败'
                    });
                }).finally(() => {
                    this.findPage();
                });
            },
            //分页查询
            findPage() {
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.post("/order/selectOrder", param).then((response) => {
                    this.dataList = response.data.data.rows;
                    this.pagination.total = response.data.data.total;
                }).catch((e) => {
                    alert(e);
                    this.$alert(e);
                    this.$message.error("未知错误")
                });
            },
            // 重置表单
            resetForm() {
                this.checkitemIds=[];
                this.formData = {};//重置数据
            },
            // 弹出添加窗口
            handleCreate() {
                //弹出新增窗口
                this.dialogFormVisible = true;
                this.activeName = 'first';
                this.resetForm();
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                this.formData = row;
                this.activeName = 'first';
                this.dialogFormVisible4Edit = true;
                this.checkitemIds[0] = this.formData.setmealId;
                axios.get("/order/selectSetmeal").then((response) => {
                    this.tableData = response.data.data;
                }).catch((e) => {
                    this.$message.error("未知错误")
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                //重新调用findPage方法进行分页查询
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                this.$confirm("确认删除当前选中记录吗？", "提示", {
                    type: 'warning'
                }).then(() => {
                    axios.get("/order/deleteOrder?id=" + row.id).then((res) => {
                        if (!res.data.flag) {//flag 失败时
                            this.$message.error(res.data.message);
                        } else {
                            this.$message({//flag 成功时
                                type: 'success',
                                message: res.data.message
                            });
                            this.findPage();
                        }
                    }).catch((e) => {
                        this.showMessage(e);
                    });
                }).catch((e) => {
                    this.$message.error('已取消删除');
                });
            },
            showMessage(e) {
                // this.$alert(e);
                if (e == "Error: Request failed with status code 403") {
                    this.$message.error('无访问权限');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            }
        }
    })
</script>
</html>